package com.xjtu.platform.user.admin.extramanage.dao;


import com.xjtu.platform.user.admin.extramanage.AdditionalApplyInfoModel;
import com.xjtu.platform.user.admin.extramanage.GetAdditionalApplyDto;
import com.xjtu.platform.user.admin.extramanage.PermitExtraDto;
import com.xjtu.platform.user.admin.extramanage.RejectExtraDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GetAdditionalApplyDao {

    @Select("select additional_apply.apply_id,additional_apply.state,additional_apply.visit_id,additional_apply.comment,user.user_name from additional_apply,first_visit,user where additional_apply.visit_id=first_visit.visit_id and first_visit.visiter_id=user.user_id")
    List<AdditionalApplyInfoModel> getAdditionalApplyInfo(GetAdditionalApplyDto getAdditionalApplyDto);

    @Select("select count(duty_id) from duty")
    String getDuty_id();

    @Insert("insert into duty values(#{user_id},#{id},#{dto.time_id},#{dto.day},#{dto.place_name},0)")
    void insertDuty(@Param("dto") PermitExtraDto permitExtraDto, @Param("id") String duty_id, @Param("user_id") String user_id);

    @Select("select visiter_id from first_visit where visit_id=#{visit_id}")
    String getUser_id(PermitExtraDto permitExtraDto);

    @Select("select count(consult_id) from consult")
    int getConsult_id();

    @Select("select max(count_num) from consult where visit_id=#{visit_id}")
    int getCount_num(PermitExtraDto permitExtraDto);

    @Insert("insert into consult(consult_id,duty_id,visit_id,count_num,state) values(#{consult_id},#{duty_id},#{dto.visit_id},#{count_num},2)")
    void insertConsult(@Param("dto") PermitExtraDto permitExtraDto, @Param("consult_id") String consult_id, @Param("duty_id") String duty_id,@Param("count_num")int count_num);

    @Update("update additional_apply set state=1 where apply_id=#{apply_id}")
    void updateAdditional_apply(PermitExtraDto permitExtraDto);

    @Update("update additional_apply set state=2 where apply_id=#{apply_id}")
    void updateRejectState(RejectExtraDto rejectExtraDto);

    @Select("select email from user,first_visit where first_visit.visit_id=#{visit_id} and first_visit.visiter_id=user_id")
    String getConsultorEmail(PermitExtraDto permitExtraDto);

    @Select("select email from user,first_visit where first_visit.visit_id=#{visit_id} and first_visit.visiter_id=user_id")
    String getConsultorReEmail(RejectExtraDto rejectExtraDto);
}
